'use strict';

const crypto = require('crypto');
const conn = require('../libs/Conn');

module.exports = async function (ctx) {
    try {
        let hash = crypto.createHash('sha256');
        let password = hash.update(ctx.request.fields.password).digest('hex');
        let user_id = ctx.session.user.user_id;
        let SQL = `select user_id from user_file where user_id = '${user_id}' and password = '${password}'`;
        let user = (await conn(SQL)).shift();
        ctx.body = user ? {success: true} : {success: false, message: '密码验证失败'};
    } catch (e) {
        ctx.body = {success: false, message: e.message};
    }
};